package com.hyzh.latte.vehicle.dmo;

import cn.hutool.core.date.DateUtil;
import com.hyzh.latte.vehicle.dmo.entity.VehicleTrackRecordPGEntity;
import lombok.*;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author songkui
 * @since 2024/5/24 20:51
 */
@Setter
@Getter
@NoArgsConstructor
@ToString
public class VehicleTrackStreamVO {
    String startTime;
    String endTime;
    String road;

    Set<CameraVO> cname;


    public static VehicleTrackStreamVO of(LocalDateTime startTime, LocalDateTime endTime, List<VehicleTrackRecordPGEntity> list){
        VehicleTrackStreamVO vehicleTrackStreamVO = new VehicleTrackStreamVO();
        vehicleTrackStreamVO.setStartTime(DateUtil.formatLocalDateTime(startTime));
        vehicleTrackStreamVO.setEndTime(DateUtil.formatLocalDateTime(endTime));
        vehicleTrackStreamVO.setRoad(list.get(0).getRoad());

        Set<CameraVO> cnameList = new HashSet<>();
        for (VehicleTrackRecordPGEntity dto : list){
            LocalDateTime addTime = dto.getAddTime();
            LocalDateTime st = addTime.minusMinutes(25);
            LocalDateTime et = addTime.plusMinutes(25);
            cnameList.add(new CameraVO(dto.getCameraCode(), (dto.getPoleCode().replace("pole", "")+"杆-"+dto.getCameraCode()+"摄像头"),  DateUtil.formatLocalDateTime(st), DateUtil.formatLocalDateTime(et)));
        }
        vehicleTrackStreamVO.setCname(cnameList);
        return vehicleTrackStreamVO;
    }

}
